package com.xiaojian.blog.service.impl;

import com.xiaojian.blog.dao.RelationshipPOMapper;
import com.xiaojian.blog.model.RelationshipPOExample;
import com.xiaojian.blog.model.RelationshipPOKey;
import com.xiaojian.blog.service.RelationshipService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RelationshioImpl implements RelationshipService {

    private static final Logger LOGGER = LoggerFactory.getLogger(RelationshioImpl.class);

    @Resource
    private RelationshipPOMapper relationshipPOMapper;


    @Override//通过主键删除
    public void deleteById(Integer cid, Integer mid) {
        RelationshipPOExample relationshipPOExample = new RelationshipPOExample();
        RelationshipPOExample.Criteria criteria = relationshipPOExample.createCriteria();
        if (cid != null) {
            criteria.andCidEqualTo(cid);
        }
        if (mid != null) {
            criteria.andMidEqualTo(mid);
        }
        relationshipPOMapper.deleteByExample(relationshipPOExample);
    }

    @Override//按照主键统计条数
    public Long countById(Integer cid, Integer mid) {
        LOGGER.debug("Enter countById method:cid={},mid={}", cid, mid);
        RelationshipPOExample relationshipPOExample = new RelationshipPOExample();
        RelationshipPOExample.Criteria criteria = relationshipPOExample.createCriteria();
        if (cid != null) {
            criteria.andCidEqualTo(cid);
        }
        if (mid != null) {
            criteria.andMidEqualTo(mid);
        }
        int num = relationshipPOMapper.countByExample(relationshipPOExample);
        LOGGER.debug("Exit countById method return num={}", num);
        return (long)num;
    }

    @Override
    public void insertVo(RelationshipPOKey relationshipPOKey) {
        relationshipPOMapper.insert(relationshipPOKey);
    }

    @Override//根据ID搜索
    public List<RelationshipPOKey> getRelationshipById(Integer cid, Integer mid) {
        RelationshipPOExample relationshipPOExample = new RelationshipPOExample();
        RelationshipPOExample.Criteria criteria = relationshipPOExample.createCriteria();
        if (cid != null) {
            criteria.andCidEqualTo(cid);
        }
        if (mid != null) {
            criteria.andMidEqualTo(mid);
        }
        return relationshipPOMapper.selectByExample(relationshipPOExample);
    }
}
